package com.byq.mm.application.cluster.client;

import com.byq.mm.abstractx.device.Device;
import com.byq.mm.abstractx.engine.CoreEnvironment;
import com.byq.mm.abstractx.protocol.Interaction;
import com.byq.mm.application.cluster.provider.ObdProvider;
import com.byq.mm.application.cluster.provider.OnoffProvider;
import com.byq.mm.foundation.cluster.client.BasicClusterClient;
import com.byq.mm.foundation.cluster.datatype.AttributeValue;
import com.byq.mm.foundation.cluster.datatype.BooleanValue;


public class OnoffClient extends BasicClusterClient {
	public OnoffClient(String cluster, Device device, CoreEnvironment e) {
		super(cluster, device, e);
		attributes.put(OnoffProvider.Define.Attributes.ONOFF, new BooleanValue(false));
	}

	public void on(){
		command(OnoffProvider.Define.ClientCommand.ON);
	}
	public void off(){
		command(OnoffProvider.Define.ClientCommand.OFF);
	}
	public void toggle(){

		command(OnoffProvider.Define.ClientCommand.TOGGLE);

	}
	BooleanValue getOnOff(){
		return (BooleanValue)attributes.get(OnoffProvider.Define.Attributes.ONOFF);
	}
	public boolean isOn(){
		
		return getOnOff().isValue();
	}
	public void refresh(){
		this.readAttribute(OnoffProvider.Define.Attributes.ONOFF);
	}

	@Override
	protected Class<? extends AttributeValue> getAttributeType(String attributeName) {
		if(attributeName.equals(OnoffProvider.Define.Attributes.ONOFF))
			return BooleanValue.class;
		return null;
	}

	@Override
	protected void init() {
		attributes.put(OnoffProvider.Define.Attributes.ONOFF,new BooleanValue(false));
		subscribed.put(OnoffProvider.Define.Attributes.ONOFF,  false);
	
		
	}
}
